<template>
  <div>
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ title }}</span>
          <!-- 单张图片 -->

          <img
            alt=""
            class="thumb"
            v-if="imgList.type === 1"
            v-lazy="imgList.images[0]"
          />
        </div>
        <!-- 三张图片 -->
        <div class="thumb-box" v-if="imgList.type === 3">
          <img
            alt=""
            class="thumb"
            v-for="(image, index) in imgList.images"
            :key="index"
            v-lazy="image"
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <span
            >作者 {{ author }} &nbsp;&nbsp; {{ comment }} 评论 &nbsp;&nbsp;
            发布日期 {{ pubTime | dateFormat }}</span
          >
          <!-- 关闭按钮 -->
          <van-icon name="cross" @click="show = true" />
          <van-action-sheet
            v-model="show"
            :actions="actions"
            @select="onSelect"
            v-if="isFirst"
          />
          <van-action-sheet
            v-model="show"
            :actions="reports"
            cancel-text="取消"
            close-on-click-action
            @select="onSelect2"
            @closed="isFirst = true"
            v-else
          />
        </div>
      </template>
    </van-cell>
  </div>
</template>

<script>
import { Toast } from 'vant'
export default {
  // 自定义属性
  props: {
    title: {
      type: String,
      default: ''
    },
    author: {
      type: String,
      default: ''
    },
    imgList: {
      type: Object,
      default: function() {
        return { type: 0 }
      }
    },
    pubTime: {
      type: String,
      default: ''
    },
    comment: {
      type: [Number, String],
      default: 0
    },
    article: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      isFirst: true,
      show: false,
      actions: [
        { name: '不感兴趣' },
        { name: '拉黑作者' },
        { name: '反馈垃圾内容' }
      ],
      reports: [
        { name: '垃圾内容' },
        { name: '低俗营销' },
        { name: '恶意引战' }
      ]
    }
  },
  created() {},
  computed: {
    artId() {
      return this.article.art_id.toString()
    }
  },
  methods: {
    onSelect(item) {
      if (item.name === '不感兴趣') {
        this.show = false
        this.$emit('remove-article', this.artId)
      } else if (item.name === '拉黑作者') {
        // this.show = false
      } else {
        this.isFirst = false
      }
    },
    onSelect2(item) {
      Toast('举报成功')
      this.$emit('remove-article', this.artId)
    }
  }
}
</script>
<style lang="less" scoped>
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.thumb {
  // 矩形黄金比例：0.618
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
